package com.wedata.weapp;

import cn.hutool.crypto.digest.MD5;
import cn.hutool.json.JSONObject;
import com.wedata.HttpUtils;

public class btw接口测试 {

    public static void main(String[] args) {
        //{"data":[{"orderNum":"6938029321299694843","toStatus":17},{"orderNum":"6938029215337288955","toStatus":17},{"orderNum":"6938029215337223419","toStatus":17},{"orderNum":"6938025701408183967","toStatus":17},{"orderNum":"6937871248329938177","fromStatus":11,"toStatus":17},{"orderNum":"6918229785902481166","toStatus":17},{"orderNum":"6918220484230151536","toStatus":17}],"appid":"16896621263","sign":"9d1a5926dfe2b943f36adec6fed9bea8"}

        JSONObject body = new JSONObject("{\"data\":[{\"orderNum\":\"6938029321299694843\",\"toStatus\":\"17\"},{\"orderNum\":\"6938029215337288955\",\"toStatus\":\"17\"}]}");
        putSignNew(body);
        String url = "https://tbtwx.gymcity.com.cn/api/v1/IntegralConversionCenter/notifyOrderStatus";
        JSONObject ss = HttpUtils.sendPost(url, body);
        System.out.println(ss);
    }

    public static void 老版本() {
        //{"data":[{"orderNum":"6938029321299694843","toStatus":17},{"orderNum":"6938029215337288955","toStatus":17},{"orderNum":"6938029215337223419","toStatus":17},{"orderNum":"6938025701408183967","toStatus":17},{"orderNum":"6937871248329938177","fromStatus":11,"toStatus":17},{"orderNum":"6918229785902481166","toStatus":17},{"orderNum":"6918220484230151536","toStatus":17}],"appid":"16896621263","sign":"9d1a5926dfe2b943f36adec6fed9bea8"}

        JSONObject param = new JSONObject("{\"data\":[{\"orderNum\":\"6938029321299694843\",\"toStatus\":17},{\"orderNum\":\"6938029215337288955\",\"toStatus\":17},{\"orderNum\":\"6938029215337223419\",\"toStatus\":17},{\"orderNum\":\"6938025701408183967\",\"toStatus\":17},{\"orderNum\":\"6937871248329938177\",\"fromStatus\":11,\"toStatus\":17},{\"orderNum\":\"6918229785902481166\",\"toStatus\":17},{\"orderNum\":\"6918220484230151536\",\"toStatus\":17}]}");
        String url = "https://tbtwx.gymcity.com.cn/api/v1/IntegralConversionCenter/notifyOrderStatus?appid=16896619360&secret_key=RzwXqLN1ESCCYXMPhuf2pMfFYTsDtyIV";
        JSONObject ss = HttpUtils.sendPost(url, param);
        System.out.println(ss);
    }
    /**
     * btw新签名
     * @param body
     * @return
     */
    public static String putSignNew(JSONObject body){
        for (String key : body.keySet()) {
            Object obj = body.get(key);
            System.out.println(obj.getClass());
            if ((obj instanceof Integer || obj instanceof Long)){
                body.put(key, String.valueOf(obj));
            }
        }
        //测试
        //body.put("appid", "16896619360");
        //String sign = MD5.create().digestHex(body +"#"+ "RzwXqLN1ESCCYXMPhuf2pMfFYTsDtyIV");
        //生产 appid=16896621263&secret_key=aHb5xWauKgkaedSY5R5NjuYCcjT88eT3
        body.put("appid", "16896621263");
        String sign = MD5.create().digestHex(body +"#"+ "aHb5xWauKgkaedSY5R5NjuYCcjT88eT3");

        body.put("sign", sign);
        System.out.println(sign);
        return sign;
    }

}
